package com.zh.entity.advanced.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;

public class SexValidConstraintValidator implements ConstraintValidator<SexValid, Byte> {
    private HashSet<Byte> set = new HashSet<>();

    @Override
    public void initialize(SexValid constraintAnnotation) {
//        ConstraintValidator.super.initialize(constraintAnnotation);
        byte[] val = constraintAnnotation.val();
        for (byte i : val) {
            set.add(i);
        }
    }

    @Override
    public boolean isValid(Byte integer, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(integer);
    }
}
